package cn.kgc.emp.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.kgc.emp.entity.Emp;
import cn.kgc.emp.service.EmpService;
import cn.kgc.emp.vo.EmpQuery;

@Controller
@RequestMapping("/emp")
public class EmpController {
	@Autowired
	private EmpService empService;
	
	@RequestMapping("/hello")
	public String hello() {
		return "success";
	}
	
	@RequestMapping(value = "/list",method = RequestMethod.GET)
	public String getEmpList(EmpQuery param, Model model ){
		List<Emp> list =empService.getEmpList(param);
		System.out.println(param);
		model.addAttribute("empList", list);
		System.out.println(list);
		/*βҳ*/
		Long count=empService.countEmpList(param);
		Long pageCount=count/param.getPageSize()+(count%param.getPageSize()==0?0:1);
		model.addAttribute("pageCount", pageCount);
		return "empList";
	}
	
}

